﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using Space.Library;
using Space.Library.Data;
using Space.Model.Data;
using Space.Model.Entity;

namespace Space.Model
{
    class DataLoader
    {
        private readonly GameRunner _gameRunner;

        public DataLoader(GameRunner gameRunner)
        {
            _gameRunner = gameRunner;
        }

        public void LoadData()
        {
            InitSimpleObjects();
            LoadModels(_gameRunner.Painter);

            CreateShips();
        }

        private void CreateShips()
        {
            // AI Ships
            ShipModel ai1 = ShipFactory.CreateDestroyerLaserShip("Mini me", Race.OwnageAI, OwnerType.AI);
            var item = new Ship(ai1, new Point(3, 3), 90);
            _gameRunner.Entities.Add(item);

            //ShipModel ai2 = ShipFactory.CreateCruiserMdShip("Crusher", Race.OwnageAI, OwnerType.AI);
            //ai2.BoardCoords = new Point(3, 6);
            //ai2.Orientation = 90;
            //_gameRunner.Entities.Add(new Ship(ai2));

            //ShipModel ai3 = ShipFactory.CreateCruiserMdShip("Pwnage", Race.OwnageAI, OwnerType.AI);
            //ai3.BoardCoords = new Point(3, 9);
            //ai3.Orientation = 90;
            //_gameRunner.Entities.Add(new Ship(ai3));

            // Player ships
            ShipModel player1 = ShipFactory.CreateCruiserMdShip("TheFun1", Race.MortMans, OwnerType.Player);
            var ship = new Ship(player1, new Point(6, 3), 270);
            _gameRunner.Entities.Add(ship);

            //ShipModel player2 = ShipFactory.CreateDestroyerLaserShip("TheFun2", Race.MortMans, OwnerType.Player);
            //player2.BoardCoords = new Point(_gameRunner.Painter.BoardXMax - 3, 6);
            //player2.Orientation = -90;
            //_gameRunner.Entities.Add(new Ship(player2));

            //ShipModel player3 = ShipFactory.CreateCruiserMdShip("TheFun3", Race.MortMans, OwnerType.Player);
            //player3.BoardCoords = new Point(_gameRunner.Painter.BoardXMax - 3, 9);
            //player3.Orientation = -90;
            //_gameRunner.Entities.Add(new Ship(player3));

        }

        private void LoadModels(Painter painter)
        {
            var basePath = "../../Resources/";

            // SHIPS
            painter.LoadModel(new ImageResource(basePath + "ships/race0/cruiser.png", "1_Cruiser"));
            painter.LoadModel(new ImageResource(basePath + "ships/race0/destroyer.png", "1_Destroyer"));

            painter.LoadModel(new ImageResource(basePath + "ships/race1/cruiser.png", "0_Cruiser"));
            painter.LoadModel(new ImageResource(basePath + "ships/race1/destroyer.png", "0_Destroyer"));

            // EFFECTS
            painter.LoadModel(new ImageResource(basePath + "effects/engine/exhaust_proton.png", "effect_engine_proton"));
        }

        private void InitSimpleObjects()
        {
            _gameRunner.Entities.Add(new Framerate());
            _gameRunner.Entities.Add(new StarField(Color.DarkGray, 10));
            _gameRunner.Entities.Add(new StarField(Color.Gray, 5));
            _gameRunner.Entities.Add(new StarField(Color.White, 3));
        }
    }
}
